package com.web.dao.impl;

import com.web.dao.OrderDao;
import com.web.domain.Order;
import com.web.domain.User;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 陈国钰 on 2016/9/7.
 */
@Repository
public class OrderDaoImpl implements OrderDao {
    @Resource
    SessionFactory factory;

    public void modify(Order order) {
        factory.getCurrentSession().save(order);
    }


    public List orderList(User user) {
        String hql = "From Order where userId = "+user.getUserId();
        return factory.getCurrentSession().createQuery(hql).list();
    }


    public Order findOrder(int orderId) {
        return (Order)factory.getCurrentSession().get(Order.class,orderId);
    }


    public void delete(Order order) {
        factory.getCurrentSession().delete(order);
    }
}
